package com.way.designpatterncodepratice.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @author liangliwei 80551025
 * @description 测试类
 * @date 2020-06-19
 */
public class Main {
    public static void main(String[] args) {

        //静态代理
        ITarget target = new Target();
        StaticProxy staticProxy = new StaticProxy(target);
        System.out.println(staticProxy.method());

        //动态代理
        InvocationHandler invocationHandler = new DynamicProxy(target);
        ITarget dynamicProxy = (ITarget) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), invocationHandler);
        System.out.println(dynamicProxy.method());


        //cglib动态代理
        ITarget cglibProxy = (ITarget) new CgLibProxy().newProxyInstance(target.getClass());
        System.out.println(cglibProxy.method());
    }
}
